package com.xt.service.impl;

import com.xt.bean.LearningPath;
import com.xt.dao.LearningPathRepository;
import com.xt.service.LearningPathService;
import com.xt.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * Created by XT on 2018/5/4.
 */
@Service
public class LearningPathServiceImpl implements LearningPathService {

    @Autowired
    private LearningPathRepository lpr;

    @Override
    public void saveOrUpdateOne(LearningPath a){

        if (StringUtils.isEmpty(a.getId())){
            //新增
            a.setCreateDate(new Date());
        }

        a.setUpdateDate(new Date());
        lpr.save(a);
    }

    @Override
    public void deleteOne(String id){
        //删除关联关系

        lpr.delete(id);
    }

    @Override
    public LearningPath getById(String id){
        return lpr.findOne(id);
    }

    @Override
    public Page<LearningPath> getLearningPathListByPage(int count, int pageNo, String sortDirection, String... sortField) {
        Page<LearningPath> learningPathsPage = lpr.findAll(PageUtil.getPageable(count,pageNo,sortDirection,sortField));
        return learningPathsPage;
    }



}

